<?php
/**************************************************************************
 * Naanal PHP Framework, Simple, Efficient and Developer Friendly
 * Copyright (C) <2010>  <Tamil Amuthan. R>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ************************************************************************/

class ClsFeature
{
	public $request=null;
	public $get=null;
	public $post=null;
	public $files=null;
	public $pdo=null;
	public $controlpanel=null;
	public $mode="create";
	private $redirect=null; 
	
	
	function __construct($controlpanel)
	{
		$this->controlpanel=$controlpanel;
		$this->pdo=ClsNaanalPDO::getInstance();
	}
	
	function getRedirect()
	{
		return $this->redirect;
	}
	
	function activate()
	{    
		$this->mode="activate";
		$objUser=new ClsWFeature();
		$objUser->set_id($this->request["id"]);
		$objUser->set_active(1);
  		$sql="update `feature` set active=:active where `id`=:id";
  		$this->pdo->setQuery($sql,$objUser);
  		$this->redirect="{$this->urlModuleParam}=feature&{$this->urlActionParam}=list";
	}
	
	function deactivate()
	{
		$this->mode="deactivate";
		$objUser=new ClsWFeature();
		$objUser->set_id($this->request["id"]);
		$objUser->set_active(0);
  		$sql="update `feature` set active=:active where `id`=:id";
  		$this->pdo->setQuery($sql,$objUser);
  		$this->redirect="{$this->urlModuleParam}=feature&{$this->urlActionParam}=list";
	}
	
	function insert()
	{       
		$this->mode="insert";
		$sql="insert into `feature` (`name`) values (:name)";
		$objUser=new ClsWFeature();
		$objUser->setArray($this->request);
      	$this->pdo->setQuery($sql,$objUser);
      	$this->redirect="{$this->urlModuleParam}=feature";
	}
	
	function update()
	{
		$this->mode="update";
		$sql="update `feature` set name=:name where `id`=:id";
		$objUser=new ClsWFeature();
		$objUser->setArray($this->request);
	    $this->pdo->setQuery($sql,$objUser);
	    $this->redirect="{$this->urlModuleParam}=feature&{$this->urlActionParam}=list";
	}
	
	function edit()
	{
		$this->mode="edit";
		$sql="select * from feature where id='{$this->request["id"]}'";
		$this->pdo->setQuery($sql);
		$objUser=new ClsWFeature();
		$objUser=$this->pdo->getObject("ClsWFeature");
		return array("form"=>$objUser);
	}
	
	function create()
	{
		$this->mode="create";
	}
	
	function delete()
	{
		$this->mode="delete";
		$objUser=new ClsWFeature();
		$objUser->set_id($this->request["id"]);
  		$sql="delete from `feature` where `id`=:id";
  		$this->pdo->setQuery($sql,$objUser);
  		$this->redirect="{$this->urlModuleParam}=feature&{$this->urlActionParam}=list";
	}
	
	function show_list()
	{
		$this->mode="list";
		$sql="select * from feature";
		$this->pdo->setQuery($sql);
		$arrObj=$this->pdo->getAllObject("ClsWFeature");
		return array("list"=>$arrObj);		
	}
	
	function render()
	{     
		$mode=$this->mode;
		if($mode=="list")
			return $this->show_list();
		else
			return $this->$mode();   	
		/*if($this->mode=="create")
		{
			return $this->create();
		}	  	
		else if($this->mode=="edit")
		{
			return $this->edit();
		}
		else if($this->mode=="insert")
		{
			return $this->insert();
		}
		else if($this->mode=="update")
		{
			return $this->update();
		}
		else if($this->mode=="delete")
		{
			return $this->delete();
		}
		else if($this->mode=="list")
		{
			return $this->show_list();
		} */
	}
}
?>